<?php

namespace App\Models\Traits;
use Carbon\Carbon;
use Illuminate\Database\Eloquent\Builder;

trait HasUserCoupon
{
	public function getUserCouponsCount()
	{
		return $this->coupons()
			->join('coupons','coupons.id','user_coupons.coupon_id')
			->where('is_used', false)
			->where(function (Builder $query) {
					$query->where('coupon_category','common')
					->orWhere('coupon_category','box');
			})
			->where('destory_at','>',Carbon::now())
		->count();
	}
}
